The present invention relates to computer graphics, and more particularly to interactive graphics systems such as home video game platforms. Still more particularly this invention relates to a system and method for providing improved fog effects in interactive three dimensional (3D) graphics systems.
Many of us have seen films containing remarkably realistic dinosaurs, aliens, animated toys and other fanciful creatures. Such animations are made possible by computer graphics. Using such techniques, a computer graphics artist can specify how each object should look and how it should change in appearance over time, and a computer then models the objects and displays them on a display such as your television or a computer screen. The computer takes care of performing the many tasks required to make sure that each part of the displayed image is colored and shaped just right based on the position and orientation of each object in a scene, the direction in which light seems to strike each object, the surface texture of each object, and other factors.
Because computer graphics generation is complex, computer-generated three-dimensional graphics just a few years ago were mostly limited to expensive specialized flight simulators, high-end graphics workstations and supercomputers. The public saw some of the images generated by these computer systems in movies and expensive television advertisements, but most of us couldn""t actually interact with the computers doing the graphics generation. All this has changed with the availability of relatively inexpensive 3D graphics platforms such as, for example, the Nintendo 64(copyright) and various 3D graphics cards now available for personal computers. It is now possible to interact with exciting 3D animations and simulations on relatively inexpensive computer graphics systems in your home or office.
A problem graphics system designers confronted in the past was to improve realism of the graphic system by closer modeling of the 3D virtual world in the graphics system to the real world. One problem with graphics systems is that they do not automatically take into account the effect that fog and other similar atmospheric conditions create in the real world. In other words, computer graphics images having a distinctive crystal clear quality throughout the image can appear unrealistic as compared to the real world. In the real world, far away objects look less clear to the viewer than do close objects. This difference in clarity results from the fact that fog, smog, mist, smoke, pollution and/or haze (hereafter simply xe2x80x9cfogxe2x80x9d) can exist in the atmosphere between the viewer and the object being viewed. As a result, the molecules making up the fog deflect light, thereby causing clarity of an object to be reduced as the distance from the viewer to the object increases. For example, in the real world, fog causes a tree that is close to a person to look clearer to that person than will a tree that is far away from that same person.
In contrast, in the virtual world of a computer graphics system, objects will all have the same clarity unless a mechanism is employed in the graphics system to simulate the effects of fog. Various solutions to this problem were offered. For example, many graphics systems have provided functions and techniques for incorporating atmospheric effects, such as fog, into a rendered scene in order to provide a more realistic view of the virtual world. For instance, the OpenGL graphics system, which provides a commonly used software interface to graphics hardware, enables a programmer to render atmospheric fog effects. OpenGL implements fogging by blending fog color with incoming fragments using a fog blending factor (f), as follows:
C=fCin+(1xe2x88x92f)Cfog
This blending factor is computer using one of the following three equations:
Exponential (GL_EXP): f=exe2x88x92(density*z)xe2x80x83xe2x80x831)
Exponential-squared (GL_EXP2): f=exe2x88x92(density*z)**2xe2x80x83xe2x80x832)
Linear (GL_LINEAR): f=(end-z)/(end-start)xe2x80x83xe2x80x833)
where z is the eye-coordinate distance between the viewpoint and the fragment center. The values for density, start and end are all specified the programmer using a particular function (i.e. glfog*( )).
Linear fog is frequently used to, for example, implement intensity depth-cuing in which objects closer to the viewer are drawn at a higher intensity. The effect of intensity as a function of distance is achieved by blending the incoming fragments with a black fog color. The exponential fog equation has some physical basis; it is the result of integrating a uniform attenuation between the object and the viewer. The exponential function can be used to, for example, represent a number of atmospheric effects using different combinations of fog colors and fog density values. By using fog, the obscured visibility of objects near the far plane can be exploited to overcome various problems such as drawing time overruns, level-of-detail transition, and database paging. However, in practice it has been found that the exponential function does not attenuate distant fragments rapidly enough. Thus, the exponential-squared fog was introduced in OpenGlL to provide a sharper fall-off in visibility. The Direct3D (DirectX) interface to graphics hardware also provides linear, exponential and exponential squared for density equations.
As explained above, various fog mechanisms have been employed in the past in order to make a 3D graphics image appear more natural and realistic. However, while significant work has been done in the past, further improvements in connection with fog simulation are desirable.
The present invention solves this problem by providing improved techniques and arrangements that further enhance the use of fog in graphics systems. The instant invention provides improved fog functions that enable new, interesting and visually enjoyable effects to be achieved in a graphics system. Additionally, the instant invention provides the ability to provide a horizontal range adjustment for the fog, thereby increasing the fog density towards the edges of the screen in order to make the effect more realistic. The invention further provides a method of sampling fog or screen space z for a normal quad and z blit is quad, when only one fog value is defined per quad. An exemplary fog calculation unit is also provided for implementing fog in accordance with the instant invention.
In accordance with one aspect provided by the invention, a method and system for simulating fog in a graphics system is provided which includes, obtaining a pixel color for a pixel, and blending a fog color with the pixel color, wherein the percentage of fog color blended with the pixel color is determined based on one of the following two fog density functions:
Fog=2xe2x88x928*(Zexe2x88x92Z0)/Z1xe2x88x92Z0) (Backwards Exponential)
Fog=2xe2x88x928*(Zexe2x88x92Z0)/Z1xe2x88x92Z0)**2 (Backwards Exponential Squared)
wherein Ze is an eye-space z value of the pixel, Z0 is an eye-space z value at which fog begins, and Z1 is an eye-space z value at which fog density substantially reaches a maximum value.
A range adjustment is preferably made to the eye-space z value (Ze) prior to applying the fog density function in order to compensate for the change in range as the viewing angle increases in the x direction away from the Z axis.